package com.chapter02;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class TestConnection3 {
    public static void main(String[] args) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException {

        // todo 准备连接数据库的要素
        String url = "jdbc:mysql://127.0.0.1:3306/myschool";
        String userName = "root";
        String userPwd = "root";

        // todo 通过反射的方式，创建一个驱动
        String driverClazz = "com.mysql.jdbc.Driver";
        Class<?> clazz = Class.forName(driverClazz);
        Driver driver = (Driver)clazz.newInstance();
        // todo 把驱动程序，交给DriverManager来管理
        DriverManager.registerDriver(driver);


        // todo 通过dirverManager来获取连接对象
        Connection connection = DriverManager.getConnection(url, userName, userPwd);

        // todo 输出连接对象
        System.out.println(connection.getClass().getName());
    }
}
